﻿using Touchality.FoursquareApi;
using WP7Square.Classes;
using System.Windows.Navigation;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using WP7Square.ViewModels;

namespace WP7Square
{

    public partial class Shout : PhoneApplicationPage
    {
        public Shout()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ListPage_Loaded);
        }

        void ListPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = new NearbyTipsViewModel();
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            var root = Application.Current.RootVisual as PhoneApplicationFrame;
            var tran = (TransitioningContentControl)VisualTreeHelper.GetChild(root, 0);
            tran.Transition = "SlideRight";
            base.OnBackKeyPress(e);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            string shout = ShoutTextBox.Text;

            if (string.IsNullOrEmpty(shout))
            {
                MessageBox.Show("Why send an empty shout?");
                return;
            }
            Location currentLocation = LocationHelper.GetCurrentLocation();
            Foursquare.CheckIn(CheckInCallback, null, string.Empty, shout, false, false, false, currentLocation.Latitude, currentLocation.Longitude);
        }

        public void CheckInCallback(CheckInCompletedEventArgs e)
        {
            string message = e.Result.message;
            var root = Application.Current.RootVisual as PhoneApplicationFrame;
            var tran = (TransitioningContentControl)VisualTreeHelper.GetChild(root, 0);
            tran.Transition = "SlideLeft";
            NavigationService.Navigate(new Uri("/MainMenu.xaml", UriKind.RelativeOrAbsolute));
        }
    }
}
